<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
 * 管理员登陆日志
 * @author 		jaypha
 * @qq			168007694
 * @email		psufool@163.com
 * @home page	www.psufool.cn
 */
class AdminLoginLog extends Admin_Controller{
	
	function __construct(){
		parent::__construct();
		$this->load->model('JayphaDB');
		if(is_null($this->adminCurrentTemplate) or empty($this->adminCurrentTemplate)){
			$this->adminCurrentTemplate = 'default';
		}
		$this->dbTablePrefix = $this->config->item('db_table_prefix');
	}
	
	function index(){
		//让CI也接受GET数据
		parse_str($this->input->server('QUERY_STRING'),$this->input->get());
		//判断是否登陆
		if(!$this->noLoginErr()) return false;
		$data['adminCurrentTemplate'] = $this->adminCurrentTemplate;
		$tvName = 'admin_login_log';

		if($this->input->server('REQUEST_METHOD')=='POST'){
			$active = $this->input->post('active');
			$del = $this->input->post('del');
			$id = $this->input->post('id');
			if(is_array($id)){
				$id = implode(',',$id);
			}
			$data['rUserName'] = $this->input->post('userName');
			$data['rLoginIP'] = $this->input->post('loginIP');
			$data['rLoginTimeStart'] = $this->input->post('loginTimeStart');
			$data['rLoginTimeEnd'] = $this->input->post('loginTimeEnd');
		}else{
			$data['rUserName'] = $this->input->get('userName');
			$data['rLoginIP'] = $this->input->get('loginIP');
			$data['rLoginTimeStart'] = $this->input->get('loginTimeStart');
			$data['rLoginTimeEnd'] = $this->input->get('loginTimeEnd');
		}
		$condition = array();
		$db_like_key = array();
		$db_like_value = array();
		if(strlen($data['rUserName'])>0){
			array_push($db_like_key,'upper(loginUserName)');
			array_push($db_like_value,strtoupper($data['rUserName']));
		}
		if(strlen($data['rLoginIP'])>0){
			array_push($db_like_key,'loginIP');
			array_push($db_like_value,$data['rLoginIP']);
		}
		if(strlen($data['rLoginTimeStart'])>0){
			$condition['loginTime >= '] = $data['rLoginTimeStart'];
		}
		if(strlen($data['rLoginTimeEnd'])>0){
			$condition['loginTime <= '] = date('Y-m-d',strtotime($data['rLoginTimeEnd']) + 24*60*60);
		}
		if(count($db_like_key)>0){
			$condition['db_like'] = array_combine($db_like_key,$db_like_value);
		}
		unset($db_like_key);
		unset($db_like_value);
		$where = $condition;

		if($this->input->server('REQUEST_METHOD')=='POST'){
			if(strtoupper($active)=='DEL'){
				if(strlen($del)==0){
					$condition['db_where_in'] = array('id',$id);
				}
				$operationData = array(
					'adminId'=>$this->session->userdata('adminUserId'),
					'title'=>'删除系统用户登陆日志',
					'url'=>$this->input->server('REQUEST_URI'),
					'remark'=>'删除系统登陆日志<!--'.$tvName.'-->，删除内容：'.json_encode($this->JayphaDB->getSingleDB($this->dbTablePrefix.$tvName,$condition))
				);
				$this->JayphaDB->setAdminOperation($operationData);
				$this->JayphaDB->delDB($this->dbTablePrefix.$tvName,$condition);
			}
		}

		unset($condition);
		$config['base_url'] = site_url("admin/adminLoginLog/index/");
		$config['total_rows'] = $this->JayphaDB->getDBCount($this->dbTablePrefix.$tvName,$where);
		$config['per_page'] = $this->JayphaDB->getConfigValue('adminPageSize');
		$config['uri_segment'] = 4;
		$config['num_links'] = 5;
		$config['first_link'] = '|<';
		$config['last_link'] = '>|';
		$config['next_link'] = '>>';
		$config['prev_link'] = '<<';

		$this->pagination->initialize($config);

		$data['currentSite'] = '常规管理<span class="split">>></span>系统配置<span class="split">>></span>管理员登陆日志列表';
		$data['phpSelf'] = $config['base_url'];
		$data['pageTag'] = '管理员登陆日志';
		$data['perm'] = 'adminLoginLog';
		$data['adminPermission'] = $this->JayphaDB->getAdminPermission($this->session->userdata('adminUserId'));
		$data['tvName'] = $tvName;
		$order = 'loginTime desc,id';
		$num = $this->uri->segment(4,0);
		$data['adminLoginLogList'] = $this->JayphaDB->getDB($config['per_page'],$num,'',$this->dbTablePrefix.$tvName,$where,$order,false);
		$this->load->view("admin/$this->adminCurrentTemplate/adminLoginLog",$data);
	}
}

/* End of file adminLoginLog.php */
/* Location: ./application/controllers/admin/adminLoginLog.php */